<?php
  
  include('lock.php');
  
  echo"<strong><h3>Check-out Details </h3></strong>";
  echo"<br/>";
  
  $total=$_POST['total'];
  $location=$_POST['location'];

  
  $q=mysql_query("SELECT location_ID FROM location WHERE location_name='$location'");
  $data_location=mysql_fetch_array($q);
  $location_id=$data_location['location_ID'];
    
  $q=mysql_query("SELECT demo_ID, COUNT(demo_ID) FROM cart WHERE user_ID='$login_session' GROUP BY demo_ID");
  
    while($data=mysql_fetch_array($q))
    {
      $num_demo_id=$data['COUNT(demo_ID)'];
      $demo_id=$data['demo_ID'];
      $ql=mysql_query("SELECT * FROM demo WHERE demo_ID='$demo_id'");
      
      while($data_fetch=mysql_fetch_array($ql))
      {
        $demo_price=number_format($data_fetch['demo_price'],2);
        $demo_name=$data_fetch['demo_name'];
        $demo_url=$data_fetch['demo_URL'];
        $demo_description=$data_fetch['demo_description'];
        
        echo"<strong>Name: </strong>" .$demo_name ."<br/>"."<br/>";
        echo"<strong>Description: </strong>" .$demo_description ."<br/>"."<br/>";
        echo"<strong>Price per item: </strong>"." $". $demo_price ."<br/>"."<br/>";
        echo"<strong>URL: </strong>" .$demo_url . "<br/>"."<br/>";
        echo"<strong>Quantity: </strong>". $num_demo_id."<br/>"."<br/>";
        echo"<br/>";
      }
      
      $query=mysql_query("SELECT game_stock FROM stock WHERE location_ID='$location_id' AND game_ID='$demo_id'");
      while($data_query=mysql_fetch_array($query))
      {
        $game_stock=$data_query['game_stock'];
        if($game_stock<$num_demo_id)
        {
          echo"** Not enough stocks for < ". $demo_name ." > in ". $location. " branch. Items will be available in 3 to 5 days. "."<br/>";
          echo"Currently, we have ". $game_stock. " available stocks for < ". $demo_name. " > in ". $location. " branch." ;
          echo"<br/>"."<br/>";
        }
      }
    }
 
  if($total == 0)
  {
    echo"<strong>Total Price: </strong>$0";
    echo"<br/>"."<br/>";
  }
  else 
  {
    echo"<strong>Total Price: </strong>$" . $total ;
    echo"<br/>"."<br/>";
  }  
  
  echo "<strong>Location: </strong>".$location."<br/>"."<br/>";
    
  $order_date =date("Y-m-d"); 
  echo "<strong>Check-Out Date: </strong>".$order_date."<br/>"."<br/>";
  
  echo "<strong>Order Status: </strong> Pending"."<br/>"."<br/>";
  
  echo"<br/>". "Do you still want to proceed?";

?>  
      <table>
      <tr>
        <form action="proceedyes2.php" method="post">
          <input type="hidden" name="total" value="<? echo $total ?>" />
          <input type="hidden" name="order_date" value="<? echo $order_date ?>" />
          <input type="hidden" name="location_id" value="<? echo $location_id ?>" />
          <input type="hidden" name="demo_id" value="<? echo $demo_id ?>" /> 
          <input type="hidden" name="demo_price" value="<? echo $demo_price ?>" /> 
          <input type="submit" onClick="window.location.href=window.location.href" value="Yes"/>  
        </form>
        
        <form action="proceedno2.php" method="post">
          <input type="submit" onClick="window.location.href=window.location.href" value="No"/>  
        </form>
      </tr>
      </table>

<?php  
?>